package NC112_进制转换;

import java.util.*;


public class Solution {
    /**
     * 进制转换
     * @param M int整型 给定整数
     * @param N int整型 转换到的进制
     * @return string字符串
     */
    public String solve (int M, int N) {
        // write code here
        if (M == 0){
            return "0";
        }
        boolean flag = true;
        if (M < 0) {
            M = -M;
            flag = false;
        }
        StringBuilder sb = new StringBuilder();
        String a = "0123456789ABCDEF";
        while (M != 0){
            sb.append(a.charAt(M % N));
            M /= N;
        }
        return flag ? sb.reverse().toString() : "-" + sb.reverse().toString();
    }
}